﻿using IXION.BLOG.COMMON.DATA;
using IXION.BLOG.DOMAIN.BLOG;
using NHibernate;
using NHibernate.Expression;
using System;
using System.Collections.Generic;
using System.Text;

namespace IXION.BLOG.DAO.BLOG
{
    /// <summary>
    /// 同用数据访问
    /// </summary>
    public class CommonDao
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="p">过滤标识 1未过期 2全部 3过期</param>
        /// <returns></returns>
        public IList<Countdown> LoadCountdowns(int p)
        {
            ISession session = NHibernateHelper.Instance.GetSession();
            ICriteria cr = session.CreateCriteria(typeof(Countdown));
            switch(p){
                case 1:
                    cr.Add(Expression.Gt("ExpireTime", DateTime.Now));
                    break;
                case 3:
                    cr.Add(Expression.Lt("ExpireTime", DateTime.Now));
                    break;
                default:
                    break;
            }
            cr.AddOrder(Order.Asc("ExpireTime"));
            return cr.List<Countdown>();
            //throw new NotImplementedException();
        }

        public IList<Mp3> LoadMp3s()
        {
            ISession session = NHibernateHelper.Instance.GetSession();
            ICriteria cr = session.CreateCriteria(typeof(Mp3));
            return cr.List<Mp3>();
            //throw new NotImplementedException();
        }
    }
}
